//
//  WCNoEmptySelectionCollectionView.m
//  WabbitCode
//
//  Created by William Towe on 1/7/09.
//  Copyright 2009 Revolution Software. All rights reserved.
//

#import "WCNoEmptySelectionCollectionView.h"
#import "NSResponder+WCExtensions.h"
#import "WCMacros.h"


@implementation WCNoEmptySelectionCollectionView
// this is the best way to prevent empty selection that i have found
- (void)mouseDown:(NSEvent *)event {
	for (NSView *view in [self subviews]) {
		if ([view hitTest:[self convertPointFromBase:[event locationInWindow]]]) {
			[super mouseDown:event];
			
			if ([event clickCount] == 2) {
				[[[self window] windowController] approveModalWindowAction:self];
			}
			
			break;
		}
	}
}

- (void)keyDown:(NSEvent *)event {
	switch ([event keyCode]) {
		case kKeyCodeEnter:
		case kKeyCodeReturn:
			[_approveButton performClick:nil];
			return;
		case kKeyCodeTab:
			[[self window] makeFirstResponder:_myNextKeyView];
			return;
	}
	
	[super keyDown:event];
}
@end
